var app = getApp();
const util = require('../../../utils/util')
    //Page Object
Page({
    data: {
        systemInfo: app.systemInfo,
        pageType: true, //true=图文，false=视频
        imageList: [
            { 'id': '1', 'src': '../../../image/1.png' },
            { 'id': '1', 'src': '../../../image/1.png' },
            { 'id': '1', 'src': '../../../image/1.png' },
            { 'id': '1', 'src': '../../../image/1.png' }
        ],
        usertype: false, //false=普通会员,true=VIP会员
        workInfo: {},
        imglist: []
    },
    goto: function(e) {

        console.log(this.data.workInfo.id)
        let id = this.data.workInfo.id
        let price = this.data.workInfo.price
        let name = this.data.workInfo.name
        wx.navigateTo({
            url: '/packageA/pages/CourseForm/index?id=' + id + '&price=' + price + '&name=' + name
        });
    },
    //options(Object)
    onLoad: function(options) {
        console.log(options.id)
        this.getInfo(options.id)
            // if (!this.data.usertype) {
            //     wx.showModal({
            //         title: '会员提示',
            //         content: '您还不是会员,点击确认开通会员',
            //         success(res) {
            //             if (res.confirm) {
            //                 console.log('用户点击确定')

        //                 wx.redirectTo({
        //                     url: '/packageA/pages/purchaseVip/index'
        //                 });
        //             } else if (res.cancel) {
        //                 console.log('用户点击取消')
        //                 wx.navigateBack();
        //             }
        //         }
        //     })
        // }
    },
    getInfo(id) {
        let _self = this
        let data = {
            openId: app.openId,
            courseId: id
        }
        util.postRequest('FinanceManage/rest/courseDetail.do', data, function(res) {
            console.log(res)
            let img = res.bean.pic_url.split(',')
            let s = []
            for (let i = 0; i < img.length; i++) {
                s.push({ src: img[i] })
            }
            console.log(s)
            _self.setData({
                workInfo: res.bean,
                imglist: s
            })
            console.log(_self.data.imglist)
        })
    },
    onReady: function() {

    },
    onShow: function() {

    },
    onHide: function() {

    },
    onUnload: function() {

    },
    onPullDownRefresh: function() {

    },
    onReachBottom: function() {

    },
    onShareAppMessage: function() {

    },
    onPageScroll: function() {

    },
    //item(index,pagePath,text)
    onTabItemTap: function(item) {

    }
});